from pygame.locals import *

maus_layout = {1:"lm",
        2:"mb",
        3:"rm"
        }

keyboard = {    32: "space",
        97: "a",
        98: "b",
        99: "c",
        100: "d",
        101: "e",
        102: "f",
        103: "g",
        104: "h",
        105: "i",
        106: "j",
        107: "k",
        108: "l",
        109: "m",
        110: "n",
        111: "o",
        112: "p",
        113: "q",
        114: "r",
        115: "s",
        116: "t",
        117: "u",
        118: "v",
        119: "w",
        120: "x",
        121: "y",
        122: "z",
        273: "up",
        276: "left",
        274: "down",
        275: "right",
        285: "f4",
        304: "shift",
        308: "alt"}

        
keys = {}
mausk = {}
maus = [0,0]
scroll=0

def inputhandler(events):
    global maus
    global scroll
    for event in events:
        if event.type == QUIT:
            return "quit"

        elif event.type == MOUSEMOTION:
            maus = event.pos
        elif event.type == MOUSEBUTTONUP:
            try:
                del mausk[maus_layout[event.button]]
            except:
                pass

        elif event.type ==MOUSEBUTTONDOWN:
            try:
                mausk[maus_layout[event.button]] = 1
            except:
                if event.button == 4:
                    scroll -= 1
                elif event.button == 5:
                    scroll += 1
                else:
                    print "unbekannter keycode %s"%event.button

        elif event.type == KEYDOWN:
            try:
                keys[keyboard[event.key]] = 1
            except:
                print "unbekannter keycode %s"%event.key

        elif event.type == KEYUP:
            try:
                del keys[keyboard[event.key]]
            except:
                pass